#include <QtGui>

#include "edge.h"
#include "propertiesdialog.h"

PropertiesDialog::PropertiesDialog(Edge *item, QWidget *parent)
    : QDialog(parent)
{
    setupUi(this);

    this->item = item;
    Color = item->Color();
	//notesTextEdit->setText(item->notes);
	//annotationTextEdit->setText(item->annotation);
    updateColorLabel(textColorLabel, Color);
}

void PropertiesDialog::on_buttonBox_accepted()
{
    item->setColor(Color);
	//item->annotation = annotationTextEdit->toPlainText();
	//item->notes = notesTextEdit->toPlainText();
    item->update();
    QDialog::accept();
}


void PropertiesDialog::on_colorButton_clicked()
{
    chooseColor(textColorLabel, &Color);
}


void PropertiesDialog::updateColorLabel(QLabel *label,
                                        const QColor &color)
{
    QPixmap pixmap(16, 16);
    pixmap.fill(color);
    label->setPixmap(pixmap);
}

void PropertiesDialog::chooseColor(QLabel *label, QColor *color)
{
    QColor newColor = QColorDialog::getColor(*color, this);
    if (newColor.isValid()) {
        *color = newColor;
        updateColorLabel(label, *color);
    }
}
